﻿#include "maintainpassword.h"
#include "ui_maintainpassword.h"
extern intListener passwordfl;

maintainPassword::maintainPassword(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::maintainPassword)
{
    ui->setupUi(this);
    this->setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
    setAttribute(Qt::WA_QuitOnClose,false);

    ui->lineEdit->setValidator(new QRegExpValidator(QRegExp("[0-9]{1}")));
    ui->lineEdit_2->setValidator(new QRegExpValidator(QRegExp("[0-9]{1}")));
    ui->lineEdit_3->setValidator(new QRegExpValidator(QRegExp("[0-9]{1}")));
    ui->lineEdit_4->setValidator(new QRegExpValidator(QRegExp("[0-9]{1}")));
    ui->lineEdit_5->setValidator(new QRegExpValidator(QRegExp("[0-9]{1}")));
    ui->lineEdit_6->setValidator(new QRegExpValidator(QRegExp("[0-9]{1}")));

}

maintainPassword::~maintainPassword()
{
    delete ui;
}

void maintainPassword::showEvent(QShowEvent *event){
    clearPassWord();
    ui->lineEdit->setFocus();
}

void maintainPassword::clearPassWord(){
    ui->lineEdit->clear();
    ui->lineEdit_2->clear();
    ui->lineEdit_3->clear();
    ui->lineEdit_4->clear();
    ui->lineEdit_5->clear();
    ui->lineEdit_6->clear();
}

void maintainPassword::on_pushButton_4_clicked()
{
    this->close();
    emit changeMainWindow();
}

void maintainPassword::on_pushButton_3_clicked()
{
    this->close();
    emit changeMainWindow();
}

void maintainPassword::on_pushButton_5_clicked()
{
    eqptinfo *eqInfo=new eqptinfo();
    QString password = eqInfo->passwordRead();
    QString inputPassWord=ui->lineEdit->text()+ui->lineEdit_2->text()+ui->lineEdit_3->text()+ui->lineEdit_4->text()+ui->lineEdit_5->text()+ui->lineEdit_6->text();
    if(inputPassWord==password){
        passwordfl.set(1);
        emit changeMacoWindow();
        this->close();
    }
    else
    {
        tcts1 = new tcts();
        tcts1->infochange("提示","error","您输入的密码错误，请重新输入",false,true);
        tcts1->show();
        clearPassWord();
        ui->lineEdit->setFocus();
    }
}

void maintainPassword::on_lineEdit_textEdited(const QString &arg1)
{
    if(ui->lineEdit->text().length()==1){
        ui->lineEdit_2->setFocus();
    }
}

void maintainPassword::on_lineEdit_2_textEdited(const QString &arg1)
{
    if(ui->lineEdit_2->text().length()==1){
        ui->lineEdit_3->setFocus();
    }else if(ui->lineEdit_2->text().length()==0){
        ui->lineEdit->setFocus();
    }
}

void maintainPassword::on_lineEdit_3_textEdited(const QString &arg1)
{
    if(ui->lineEdit_3->text().length()==1){
        ui->lineEdit_4->setFocus();
    }else if(ui->lineEdit_3->text().length()==0){
        ui->lineEdit_2->setFocus();
    }
}

void maintainPassword::on_lineEdit_4_textEdited(const QString &arg1)
{
    if(ui->lineEdit_4->text().length()==1){
        ui->lineEdit_5->setFocus();
    }else if(ui->lineEdit_4->text().length()==0){
        ui->lineEdit_3->setFocus();
    }
}

void maintainPassword::on_lineEdit_5_textEdited(const QString &arg1)
{
    if(ui->lineEdit_5->text().length()==1){
        ui->lineEdit_6->setFocus();
    }else if(ui->lineEdit_5->text().length()==0){
        ui->lineEdit_4->setFocus();
    }
}

void maintainPassword::on_lineEdit_6_textEdited(const QString &arg1)
{
    if(ui->lineEdit_6->text().length()==1){
        on_pushButton_5_clicked();
    }else if(ui->lineEdit_6->text().length()==0){
        ui->lineEdit_5->setFocus();
    }
}
